﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;

namespace AddPreDialNumber
{
    public partial class MainPage : PhoneApplicationPage
    {
        // 构造函数
        public MainPage()
        {
            InitializeComponent();
            ChosePhoneNumber();
        }

        private void ChosePhoneNumber()
        {
            PhoneNumberChooserTask phoneNumberChooserTask = new PhoneNumberChooserTask();
            phoneNumberChooserTask.Show();
            phoneNumberChooserTask.Completed += (s, e) =>
            {
                if (e.TaskResult == TaskResult.OK)
                {
                    txtBoxName.Text = e.DisplayName;
                    txtBoxPhone.Text = e.PhoneNumber;

                }
            };
        }

        private void Dial_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                PhoneCallTask phoneCallTask = new PhoneCallTask();
                phoneCallTask.PhoneNumber =txtBoxPreDailNumber.Text +  txtBoxPhone.Text;
                phoneCallTask.Show();
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
            }

        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            base.OnBackKeyPress(e);

        }

        private void btnReChose_Click(object sender, RoutedEventArgs e)
        {
            ChosePhoneNumber();
        }

       
    }
}